# -*- coding = utf-8 -*-
# @Time    : 2025/3/13 下午7:13
# @Author  : yqk
# @File    : urllib.py
# @Software: PyCharm

# import urllib.request
#
# response = urllib.request.urlopen("http://www.baidu.com")
# print(response.read().decode('utf-8'))

# 发送 post 请求
# import urllib.request
# import urllib.parse
# import urllib.error
# data = bytes(urllib.parse.urlencode({'hello': 'world'}), encoding='utf8')
# response = urllib.request.urlopen('http://httpbin.org/post', data=data)
# print(response.read().decode('utf-8'))

# 发送 get 请求
import urllib.request
try:
    response = urllib.request.urlopen('http://httpbin.org/get', timeout=0.01)
    print(response.read().decode('utf-8'))
except Exception as e:
    print(e)